<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>diclist</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 0.20" />
</head>

<body>
<?php
/*
 *      diclist.php
 *      
 *      Copyright 2011 Vitaliy Rakitin <virak@ukr.net>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
 
require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/osmetadata.php");

function testform(&$dictionary) {
	echo "<pre>".print_r($dictionary->items->getall(),1)."</pre>";
}

function displayform(&$dictionary) {
	$out = "<div style='text-align:center;'>";
/*
	$out .= "<form name='edit' action='' method='post'>";
	$out .= "<input type='submit' name='update' value='Обновить'>";
	$out .= "</form>";
*/
	$out .= "<a href='dicitem.php?dictionary=".$dictionary->uuid."&item='>Insert</a></div>";
	
	$out .= "<table align='center' style='border: solid black 1px;'>";
	$out .= "<tr>";
	$out .= "<th style='border: solid black 1px;'>E</th>";
	foreach ($dictionary->fields->getall() as $field) {
		$out .= "<th style='border: solid black 1px;'><a href='diclist.php?dictionary=".$dictionary->uuid."&sortby=".$field->uuid;
		if ($dictionary->sortby == $field->uuid) {
			if ($dictionary->direction == "ASC") {
				$out .= "&direction=DESC'>".$field->name." ^";//</th>";
			} else {
				$out .= "&direction=ASC'>".$field->name." v";//</th>";
			}
		} else {
			$out .= "&direction=ASC'>".$field->name;
		}
		$out .= "</a></th>";
	}
	$out .= "</tr>";

	foreach ($dictionary->items->getall() as $item) {

			$out .= "<tr style='background-color:#F0F0F0;color:#000000;padding: 0px;'>";
			$out .= "<td><a href='dicitem.php?dictionary=".$dictionary->uuid."&item=".$item->uuid."'>edit</a></td>";

		foreach($dictionary->fields->getall() as $field) {
			//$out .= "<td style='border: solid black 1px;'>";
			$out .= "<td >";
			switch ($field->type) {
				case "float":
				case "varchar":// {$out .= $item[$field["id"]]; break;}
				case "date": {$out .= $item->fields->byuuid($field->uuid)->value; break;}
/*
				case "link": {
					$lufield = $this->object->items->byuuid($item->fields->byuuid($field->uuid)->value)->fields->byuuid($field->uuid);
					$out .= $GLOBALS["metadata"]->objects->byuuid($lufield->luobject)->items->byuuid($lufield->sense)->fields->byuuid($lufield->ludisplay)->value;
					break;
				}
*/
			}
			$out .= "</td>";
		}
		$out .= "</tr>";
	}
	$out .= "</table>";
	echo $out;
}

if (!array_key_exists("dictionary",$_GET)) {
	echo "Необходимо указать словарь";
	exit;
} else {
	//if (!array_key_exists($_GET["dictionary"],$_SESSION)) {
		if (!$dictionary = $metadata->dictionaries->byuuid($_GET["dictionary"])) {
			echo "Словарь с таким uuid не найден";
			exit;
		}
/*
	} else {
		$dictionary = &$_SESSION[$_GET["dictionary"]];
	}
*/
}

if (array_key_exists("sortby",$_GET)) {$dictionary->sortby = $_GET["sortby"];}
if (array_key_exists("direction",$_GET)) {$dictionary->direction = $_GET["direction"];}

if (array_key_exists("insert",$_POST)) {

} elseif (array_key_exists("edit",$_POST)) {
	
} elseif (array_key_exists("update",$_POST)) {
	//$_SESSION[$dictionary->uuid] = $dictionary = $metadata->dictionaries->byuuid($_GET["dictionary"]);
	//displayform($dictionary);
} else {
	displayform($dictionary);
	//testform($dictionary);
}

?>

	
</body>

</html>
